<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$ColumnType = 3;
isset($_GET['Rela']) ? $Rela = $_GET['Rela'] : $Rela = 0;
!is_numeric($_GET['page']) ? $page = 1 : $page = (int)($_GET['page']);
$PageCount = $DownloadManagePage;

if($_GET['Action'] == 'Del'){
	if(!is_numeric($_GET['ID'])) MsgBox (1,'ID参数出现非数字错误！','-1');
	$pics = new pics();
	$pics->remove_upload_files($_GET['ID'],4);			
	if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "download` WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1;")){
		AdminLog(3,$Lang,'删除下载资源(ID:' . $_GET['ID'] . ')，结果：删除成功！'); 
		MsgBox (0,'','DownloadManage.php?Lang=' . $Lang . '&page=' . $page . '&Rela=' . $Rela);		
	}else{
		AdminLog(3,$Lang,'删除下载资源(ID:' . $_GET['ID'] . ')，结果：删除失败！'); 
		MsgBox (1,'删除下载资源失败！','-1');	
	}	
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
</head>

<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td><?php TopLang();?></td>
	<td align="right"><select OnChange="window.open(this.options[this.selectedIndex].value,'_self')" size="1">
<?php
echo '<option value="DownloadManage.php?Lang=' . $Lang . '">==显示所有类别==</option>' . "\n";
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ){
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	if($Rela != $Rs[$i][1]){
		echo '<option value="DownloadManage.php?Lang=' . $Lang . '&Rela=' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}else{
		echo '<option selected="selected" value="DownloadManage.php?Lang=' . $Lang . '&Rela=' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}
	unset($Spaces);
}
unset($Rs,$i,$x);
?>  	
</select>
	<input type="button" value="添加资源" onClick="javascript:location.href='DownloadAdd.php?Lang=<?php echo $Lang?>'">
	<input type="button" value="类别管理" onClick="javascript:location.href='DownloadColumnManage.php?Lang=<?php echo $Lang?>'">
</td>
	</tr>
</table>

<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td colspan="5" align="center" class="Main_Title">下载资源管理<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="center"><strong>资源标题</strong></td>
    <td align="center"><strong>下载地址</strong></td>
    <td align="center"><strong>添加时间</strong></td>
    <td align="center"><strong>下载次数</strong></td>
    <td align="center"><strong>管理选项</strong></td>
  </tr>
<?php
$SQL = "SELECT `ID`,`DownloadType`,`DownloadTitle`,`DownloadUrl`,`DownloadViews`,`DownloadAddDate` FROM `" . $dbprefix . "download` "; 
$SQL .= "WHERE `DownloadLang` = '" . $Lang . "' ";
if($Rela != 0) $SQL .= "&& `DownloadRela` LIKE '%" . $Rela . "%' ";
$RsCount = count($db->SelectSQL($SQL));
$SQL .= "ORDER BY `ID` DESC "; 
$SQL .= "LIMIT " . ($page-1)*$PageCount . "," . $PageCount;
foreach ($db->SelectSQL($SQL) as $i => $n){
	Html($n);
	$n[1] == 0 ? $DownloadUrl = '<a target="_blank" href="../' . $n[3] . '">' . substr($n[3],0,50) . '</a>' : $DownloadUrl = '<a target="_blank" href="' . $n[3] . '">' . substr($n[3],0,50) . '</a>';
	echo '<tr class="odd">
  	<td height="20" align="center">' . $n[2] . '</td>
  	<td align="center">' . $DownloadUrl . '</td>
  	<td align="center">' . $n[5] . '</td>
  	<td align="center" class="red">' . $n[4] . '</td>
  	<td align="center"><a href="DownloadUpDate.php?Lang=' . $Lang . '&page=' . $page . '&Rela=' . $Rela . '&ID=' . $n[0] . '">修改</a> | 
	<a onClick="return confirm(\'确定要删除该资源吗？\');" href="DownloadManage.php?Lang=' . $Lang . '&page=' . $page . '&Rela=' . $Rela . '&Action=Del&ID=' . $n[0] . '">删除</a></td>
  	</tr>';
}
?>
<tr class="odd">
    <td height="30" colspan="5" align="center"><?php if($RsCount>0) {echo pages('Lang=' . $Lang . '&Rela=' . $Rela);} else {echo '没有相关数据！<a href="DownloadAdd.php?Lang=' . $Lang . '">添加下载资源</a>';};?></td>
    </tr>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;"></td>
	</tr>
</table>  
<?php unset($SQL,$i,$n,$PageCount,$RsCount,$DownloadUrl);  ?>
</body>
</html>
